﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ForzaGT3.Data;

namespace ForzaGT3.Areas.Admin.Controllers
{
    public partial class CountryController : Controller
    {
        //
        // GET: /Admin/Country/

        public virtual ActionResult Index()
        {
            var data = Country.GetAll()
                .OrderByDescending(x => x.CreatedDate);

            ViewBag.totalRecords = data.Count();

            return View(data);
        }

        public virtual ActionResult Add()
        {
            return View();
        }

        [HttpPost]
        public virtual ActionResult Add(Country model)
        {
            if (ModelState.IsValid)
            {

                return RedirectToAction(MVC.Admin.Country.Index());
            }
            return View(model);
        }

        public virtual ActionResult Edit(Guid Id)
        {
            Country data = Country.GetById(Id);
            Country model = new Country();
            if (data != null)
            {

            }
            return View(model);
        }

        [HttpPost]
        public virtual ActionResult Edit(Country model)
        {
            Country data = Country.GetById(model.CountryId);
            if (data != null)
            {


                return RedirectToAction(MVC.Admin.Country.Index());
            }

            return View(model);
        }

        public virtual ActionResult Delete(Guid Id)
        {
            Country data = Country.GetById(Id);
            if (data != null)
            {
                data.IsDeleted = true;
                data.Update();
            }

            return RedirectToAction(MVC.Admin.Country.Index());
        }
    }
}
